package shop

import (
	"fmt"
	"log"
	"tangzq/shopping/common/model"
	"tangzq/shopping/stock"
	"time"
)

func Create(req model.CreateReq, stockObj *stock.Stock) (resp model.CreateResp, err error) {
	if stockObj == nil {
		log.Fatal("stock obj can not be nil")
	}

	resp.Msg = fmt.Sprintf("用户来买东西啦!")
	resp.UserId = req.UserId
	resp.GoodsId = req.GoodsId
	resp.Count = req.Count
	resp.OrderNumber = fmt.Sprintf("%d%d%s-%d", resp.UserId, resp.GoodsId, time.Now().Format("20060102150405"), resp.Count)

	stockObj.Decrease(1, true)
	// temp := stockObj.Get()
	// time.Sleep(time.Millisecond * 10)
	// current := temp - 1
	// time.Sleep(time.Millisecond * 10)
	// stockObj.Save(current)

	return
}
